<template>
        <el-card shadow="never" style="max-height: 70vh; overflow: auto">
            <el-form ref="form" :model="form" :rules="rules" label-width="90px" :disabled="disabled">
                <el-form-item label="id:" prop="id" v-show="false">
                    <el-input v-model="form.id" disabled />
                </el-form-item>
                <el-form-item label="回复ID:" prop="reply_id">
                    <el-input-number v-model="form.reply_id" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="动态ID:" prop="post_id">
                    <el-input-number v-model="form.post_id" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="评论ID:" prop="comment_id">
                    <el-input-number v-model="form.comment_id" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="所属用户:" prop="user_id">
                    <el-input-number v-model="form.user_id" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="昵称:" prop="nickname">
                    <el-input v-model="form.nickname" placeholder="请输入昵称" clearable />
                </el-form-item>
                <el-form-item label="头像:" prop="avatar">
                    <ImageUpload v-model="form.avatar" />
                </el-form-item>
                <el-form-item label="被回复人:" prop="reply_user_id">
                    <el-input-number v-model="form.reply_user_id" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="被回复人昵称:" prop="reply_nickname">
                    <el-input v-model="form.reply_nickname" placeholder="请输入被回复人昵称" clearable />
                </el-form-item>
                <el-form-item label="被回复人头像:" prop="reply_avatar">
                    <ImageUpload v-model="form.reply_avatar" />
                </el-form-item>
                <el-form-item label="内容:" prop="content">
                    <el-input v-model="form.content" placeholder="请输入内容" clearable />
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="submitForm">确认 </el-button>
                    <el-button type="warning" @click="cancel">取消 </el-button>
                </el-form-item>
            </el-form>
        </el-card>
</template>

<script>
import { regionData } from 'element-china-area-data'
export default {
    name: 'EditForm',
    props: {
        findFormData: {
            type: Object,
            default: {}
        },
        editFormParams: {
            type: Object,
            default: {}
        },
        // 表单是否禁用
        disabled: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            // 编辑表单验证规则
            rules: {
                reply_id: [{ required: true, message: "请输入回复ID", trigger: "blur" }],
                post_id: [{ required: true, message: "请输入动态ID", trigger: "blur" }],
                comment_id: [{ required: true, message: "请输入评论ID", trigger: "blur" }],
                user_id: [{ required: true, message: "请输入所属用户", trigger: "blur" }],
                nickname: [{ required: true, message: "请输入昵称", trigger: "blur" }],
                avatar: [{ required: true, message: "请输入头像", trigger: "blur" }],
                reply_user_id: [{ required: true, message: "请输入被回复人", trigger: "blur" }],
                reply_nickname: [{ required: true, message: "请输入被回复人昵称", trigger: "blur" }],
                reply_avatar: [{ required: true, message: "请输入被回复人头像", trigger: "blur" }],
                content: [{ required: true, message: "请输入内容", trigger: "blur" }],

            },
            form: {  },
            // 区域选择配置
            areaOptions: regionData,

        }
    },
    watch: {
        findFormData: {
           handler(nval) {
                if (JSON.stringify(nval) != '{}') {
                    this.$nextTick(() => {
                        this.form = nval
                    })
                }
            },
            immediate: true,
            deep: false,
        },
    },
    methods: {
        // 取消按钮
        cancel() {
            this.$emit('editFormCancel')
        },

        submitForm() {
            this.$refs['form'].validate((valid, obj) => {
                if (valid) {
                    this.$emit('submitForm', this.form)
                }
            })
        },

        // 表单重置
        reset() {
            this.resetForm('form')
        }
    }
}
</script>
